<template>
	<view>
		<!-- #ifdef APP-->
		<view class='status'></view>
		<!-- #endif -->
		<form @submit="formSubmit" report-submit='true' v-if="1==2">
			<view class='addAddress pad30'>
				<view class='list borRadius14'>
					<view class='item acea-row row-between-wrapper' style="border: none;">
						<view class='name'>姓名</view>
						<input type='text' placeholder='请输入姓名' placeholder-style="color:#ccc;" name='realName'
							:value="userAddress.realName" placeholder-class='placeholder' maxlength="4"></input>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view class='name'>联系电话</view>
						<input type='number' placeholder='请输入联系电话' placeholder-style="color:#ccc;" name="phone"
							:value='userAddress.phone' placeholder-class='placeholder' maxlength="11"></input>
					</view>
					<view class='item acea-row row-between-wrapper relative'>
						<view class='name'>所在地区</view>
						<view class="address">
							<picker mode="multiSelector" @change="bindRegionChange"
								@columnchange="bindMultiPickerColumnChange" :value="valueRegion" :range="multiArray">
								<view class='acea-row'>
									<view class="picker line1">{{region[0]}}，{{region[1]}}，{{region[2]}}</view>
									<view class='iconfont icon-xiangyou abs_right'></view>
								</view>
							</picker>
						</view>
					</view>
					<view class='item acea-row row-between-wrapper relative'>
						<view class='name'>详细营员</view>
						<input type='text' placeholder='请填写具体营员' placeholder-style="color:#ccc;" name='detail'
							placeholder-class='placeholder' v-model='userAddress.detail' maxlength="18"></input>
						<view class='iconfont icon-dizhi font-color abs_right' @tap="chooseLocation"></view>
					</view>
				</view>
				<view class='default acea-row row-middle borRadius14'>
					<checkbox-group @change='ChangeIsDefault'>
						<checkbox :checked="userAddress.isDefault" />设置为默认营员
					</checkbox-group>
				</view>

				<button class='keepBnt bg-color' form-type="submit">立即保存</button>
				<!-- #ifdef MP -->
				<view class="wechatAddress" v-if="!id" @click="getWxAddress">导入微信营员</view>
				<!-- #endif -->
				<!-- #ifdef H5 -->
				<view class="wechatAddress" v-if="this.$wechat.isWeixin() && !id" @click="getAddress">导入微信营员</view>
				<!-- #endif -->
			</view>
		</form>


		<view class='addAddress pad30'>
			<view class='list borRadius14'>
				<view class='item acea-row row-between-wrapper' style="border: none;">
					<view class='name required'>营员姓名</view>
					<input type='text' placeholder='请输入姓名' placeholder-style="color:#ccc;" name='realName'
						v-model="formData.camperName" placeholder-class='placeholder' maxlength="4"></input>
				</view>

				<view class='item acea-row row-between-wrapper1'>
					<view class='name required'>营员性别</view>
					<radio-group @change="radioChange" class="row">
						<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in sex" :key="item.value">
							<view class="row">
								<radio :value="item.value" :checked="item.value == formData.camperSex" />
								<view>{{ item.name }}</view>
							</view>
						</label>
					</radio-group>
				</view>
				<view class='item acea-row row-between-wrapper'>
					<view class='name required'>营员年龄</view>
					<input type='number' placeholder='请输入年龄' placeholder-style="color:#ccc;" name='age'
						v-model="formData.camperAge" placeholder-class='placeholder' maxlength="2"></input>
				</view>
				<picker mode="date" @change="bindPickerChange3" :value="formData.camperBirthday">

					<view class='item acea-row row-between-wrapper'>
						<view class='name required'>营员生日</view>
						<view class='acea-row'></view>
						<view class="picker line1">{{formData.camperBirthday.replace(' 00:00:00', '')}}</view>
						<!-- <view class='iconfont icon-xiangyou abs_right'></view> -->
					</view>
				</picker>
			</view>
		</view>

		<view class='addAddress pad30'>
			<view class='list borRadius14'>

				<view class='item acea-row row-between-wrapper'>
					<view class='name required'>民 族</view>
					<input type='text' placeholder='请输入民族' placeholder-style="color:#ccc;" name='nationality'
						v-model="formData.camperNationality" placeholder-class='placeholder' maxlength="4"></input>
				</view>


				<view class='item acea-row row-between-wrapper'>
					<view class='name required'>证件类型</view>
					<picker mode="selector" @change="bindPickerChange2" :value="index2" :range="idType">
						<view class="picker line1">{{ idType[formData.camperIdType]}}</view>
						<!-- <view class='iconfont icon-xiangyou abs_right'></view> -->
					</picker>
				</view>
				<view class='item acea-row row-between-wrapper'>
					<view class='name required'>证件号码</view>
					<input type="idcard" placeholder='请输入证件号码' placeholder-style="color:#ccc;" name='idNumber'
						v-model="formData.camperIdNumber" placeholder-class='placeholder' maxlength="18"></input>
				</view>
			</view>
		</view>

		<view class='addAddress pad30'>
			<view class="list borRadius14">
				<view class='item acea-row row-between-wrapper'>
					<view class='name required'>身高(厘米)</view>
					<input type='decimal' placeholder='请输入营员身高(厘米)' placeholder-style="color:#ccc;" name='height'
						v-model="formData.camperHeight" placeholder-class='placeholder' maxlength="4"></input>
				</view>
				<view class='item acea-row row-between-wrapper'>
					<view class='name required'>体重(kg)</view>
					<input type='decimal' placeholder='请输入营员体重(kg)' placeholder-style="color:#ccc;" name='weight'
						v-model="formData.camperWeight" placeholder-class='placeholder' maxlength="4"></input>
				</view>

				<view class='item acea-row row-between-wrapper'>
					<view class='name'>健康状况</view>
					<input type='text' placeholder='请输入健康状况' placeholder-style="color:#ccc;" name='healthStatus'
						v-model="formData.camperHealthStatus" placeholder-class='placeholder' maxlength="18"></input>
				</view>
			</view>
		</view>

		<view class='addAddress pad30'>
			<view class='list borRadius14'>
				<view class='item acea-row row-between-wrapper'>
					<view class='name'>兴趣爱好</view>
					<input type='text' placeholder='请输入兴趣爱好' placeholder-style="color:#ccc;" name='hobby'
						v-model="formData.camperHobby" placeholder-class='placeholder' maxlength="18"></input>
				</view>
				<view class="hobby-wait">
					<view class='hobby-detail' @click="chooseHobby('游泳')">游泳</view>
					<view class='hobby-detail' @click="chooseHobby('篮球')">篮球</view>
					<view class='hobby-detail' @click="chooseHobby('画画')">画画</view>
				</view>
			</view>
		</view>

		<view class='addAddress pad30'>
			<view class='list borRadius14'>

				<view class='item acea-row row-between-wrapper'>
					<view class='name required'>监护人姓名</view>
					<input type='text' placeholder='请输入监护人姓名' placeholder-style="color:#ccc;" name='guardianName'
						v-model="formData.camperGuardianName" placeholder-class='placeholder' maxlength="18"></input>
				</view>
				<view class='item acea-row row-between-wrapper'>
					<view class='name required'>监护人电话</view>
					<input type='text' placeholder='请输入监护人电话' placeholder-style="color:#ccc;" name='guardianPhone'
						v-model="formData.camperGuardianPhone" placeholder-class='placeholder' maxlength="18"></input>
				</view>
				<view class='item acea-row row-between-wrapper'>
					<view class='name required'>与营员关系</view>
					<input type='text' placeholder='请输入与营员关系' placeholder-style="color:#ccc;" name='relationship'
						v-model="formData.relationship" placeholder-class='placeholder' maxlength="18"></input>
				</view>
				<view class='item acea-row row-between-wrapper'>
					<view class='name required wrap'>紧急电话</view>
					<input type='text' placeholder='请输入紧急联系人电话' placeholder-style="color:#ccc;"
						name='emergencyPhoneNumber' v-model="formData.emergencyPhoneNumber"
						placeholder-class='placeholder' maxlength="18"></input>
				</view>
			</view>
		</view>
		<view class='addAddress pad30'>
			<view class='list borRadius14'>
				<view class='item acea-row row-between-wrapper'>
					<view class='name required'>详细地址</view>
					<input type='text' placeholder='请输入详细地址' placeholder-style="color:#ccc;" name='detailedAddress'
						v-model="formData.detailedAddress" placeholder-class='placeholder' maxlength="18"></input>
				</view>
			</view>
		</view>
		<view class='addAddress pad30'>
			<view class='list borRadius14'>
				<view class='item acea-row row-between-wrapper'>
					<view class='name'>家长寄语</view>
					<input type='text' placeholder='请输入家长寄语' placeholder-style="color:#ccc;" name='parentMessage'
						v-model="formData.camperParentMessage" placeholder-class='placeholder' maxlength="18"></input>
				</view>
			</view>
		</view>

		<view class='addAddress pad30'>
			<view class='list borRadius14'>
				<view class='item acea-row row-between-wrapper'>
					<view class='name'>如何获取</view>
					<input type='text' placeholder='请输入如何获取' placeholder-style="color:#ccc;" name='howToObtain'
						v-model="formData.howToObtain" placeholder-class='placeholder' maxlength="18"></input>
				</view>
				<view class='item acea-row row-between-wrapper'>
					<view class='name'>备 注</view>
					<input type='text' placeholder='请输入备注' placeholder-style="color:#ccc;" name='notes'
						v-model="formData.notes" placeholder-class='placeholder' maxlength="18"></input>
				</view>
			</view>
		</view>

		<view class='addAddress pad30' style="background-color: initial;">
			<view class='list borRadius14' style="background-color: initial;">
				<button class='keepBnt bg-color' @click="save">立即保存</button>
			</view>
		</view>

		<!-- <button class='keepBnt bg-color' form-type="submit">立即保存</button> -->
		<!-- #ifdef MP -->
		<!-- <view class="wechatAddress" v-if="!id" @click="getWxAddress">导入微信营员</view> -->
		<!-- #endif -->
		<!-- #ifdef H5 -->
		<!-- <view class="wechatAddress" v-if="this.$wechat.isWeixin() && !id" @click="getAddress">导入微信营员</view> -->
		<!-- #endif -->
	</view>
	<!-- #ifdef MP -->
	<!-- <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
	<!-- #endif -->
	<!-- <home></home> -->
	</view>
</template>

<script>
	import {
		editAddress,
		getAddressDetail
	} from '@/api/user.js';
	import {
		getCity
	} from '@/api/api.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	// #ifdef MP
	import authorize from '@/components/Authorize';
	// #endif
	import home from '@/components/home';
	// import city from '@/utils/cityData';
	let app = getApp();
	export default {
		components: {
			// #ifdef MP
			authorize,
			// #endif
			home
		},
		data() {
			return {
				regionDval: ['浙江省', '杭州市', '滨江区'],
				cartId: '', //购物车id
				pinkId: 0, //拼团id
				couponId: 0, //优惠券id
				id: 0, //营员id
				userAddress: {
					isDefault: false
				}, //营员详情
				region: ['省', '市', '区'],
				valueRegion: [0, 0, 0],
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false, //是否隐藏授权
				district: [],
				multiArray: [],
				multiIndex: [0, 0, 0],
				cityId: 0,
				defaultRegion: ['广东省', '广州市', '番禺区'],
				defaultRegionCode: '440113',
				bargain: false, //是否是砍价
				combination: false, //是否是拼团
				secKill: false, //是否是秒杀
				formData: {
					// "image": "http://example.com/path/to/image.jpg",
					// "camperName": "张三",
					// "camperSex": 1,
					// "camperAge": 12,
					// "camperIdType": 1,
					// "camperIdNumber": "123456789012345678",
					// "camperBirthday": "2012-05-14T10:30:00",
					// "camperNationality": "汉族",
					// "camperHeight": 1.45,
					// "camperWeight": 40.5,
					// "camperHobby": "游泳, 篮球",
					// "camperHealthStatus": "健康",
					// "camperParentMessage": "希望你能度过一个愉快的夏令营时光！",
					// "camperGuardianName": "李四",
					// "camperGuardianPhone": "13812345678",
					// "emergencyPhoneNumber": "13987654321",
					// "relationship": "父亲",
					// "detailedAddress": "北京市朝阳区某街道123号",
					// "howToObtain": "通过学校报名",
					// "notes": "无特殊需求",


					"image": "",
					"camperName": "",
					"camperSex": 1,
					"camperAge": "",
					"camperIdType": 1,
					"camperIdNumber": "",
					"camperBirthday": "",
					"camperNationality": "",
					"camperHeight": "",
					"camperWeight": "",
					"camperHobby": "",
					"camperHealthStatus": "",
					"camperParentMessage": "",
					"camperGuardianName": "",
					"camperGuardianPhone": "",
					"emergencyPhoneNumber": "",
					"relationship": "",
					"detailedAddress": "",
					"howToObtain": "",
					"notes": "",
					"userId": uni.getStorageSync('UID')
				},
				sex: [{
						name: '男',
						value: 1
					},
					{
						name: '女',
						value: 2
					}
				],
				idType: ["请选择", '身份证', '护照'],
			};
		},
		computed: mapGetters(['isLogin']),
		watch: {
			isLogin: {
				handler: function(newV, oldV) {
					if (newV) {
						this.getUserAddress();
						this.getCityList();
					}
				},
				deep: true
			}
		},
		onLoad(options) {
			if (this.isLogin) {
				this.preOrderNo = options.preOrderNo || 0;
				this.id = options.id || 0;
				uni.setNavigationBarTitle({
					title: options.id ? '修改营员' : '添加营员'
				})
				this.getUserAddress();
				if (this.$Cache.has('cityList')) {
					//检测城市数据是否存在缓存，有的话从缓存取，没有的话请求接口
					this.district = this.$Cache.getItem('cityList')
					this.initialize();
				} else {
					this.getCityList();
				}
			} else {
				toLogin();
			}
		},
		methods: {
			bindPickerChange3(e) {
				console.log(e);
				this.formData.camperBirthday = e.detail.value

			},
			chooseHobby(hobby) {
				if (!this.formData.camperHobby.includes(hobby)) {
					this.formData.camperHobby += ',' + hobby
				}
			},
			radioChange(e) {
				this.formData.camperSex = e.detail.value
			},
			idTypeChange(e) {
				this.formData.camperIdType = e.detail.value
			},
			save() {
				if (this.formData.camperName == '') {
					uni.showToast({
						title: '请输入营员姓名',
						icon: 'none'
					})
					return
				}
				if (this.formData.camperSex == '') {
					uni.showToast({
						title: '请选择营员性别',
						icon: 'none'
					})
					return
				}
				if (this.formData.camperAge == '') {
					uni.showToast({
						title: '请输入营员年龄',
						icon: 'none'
					})
					return
				}
				if (this.formData.camperIdType == '') {
					uni.showToast({
						title: '请选择营员证件类型',
						icon: 'none'
					})
					return
				}
				if (this.formData.camperIdNumber == '') {
					uni.showToast({
						title: '请输入营员证件号码',
						icon: 'none'
					})
					return
				}
				if (this.formData.camperBirthday == '') {
					uni.showToast({
						title: '请选择营员出生日期',
						icon: 'none'
					})
					return
				}
				if (this.formData.camperHeight == '') {
					uni.showToast({
						title: '请输入营员身高',
						icon: 'none'
					})
					return
				}
				if (this.formData.camperWeight == '') {
					uni.showToast({
						title: '请输入营员体重',
						icon: 'none'
					})
					return
				}
				if (this.formData.camperGuardianName == '') {
					uni.showToast({
						title: '请输入监护人姓名',
						icon: 'none'
					})
					return
				}
				if (this.formData.camperNationality == '') {
					uni.showToast({
						title: '请输入营员民族',
						icon: 'none'
					})
					return
				}
				if (this.formData.camperGuardianPhone == '') {
					uni.showToast({
						title: '请输入监护人电话',
						icon: 'none'
					})
					return
				}
				if (this.formData.relationship == '') {
					uni.showToast({
						title: '请输入监护人与营员关系',
						icon: 'none'
					})
					return
				}
				if (this.formData.emergencyPhoneNumber == '') {
					uni.showToast({
						title: '请输入紧急联系人电话',
						icon: 'none'
					})
					return
				}
				if (this.formData.detailedAddress == '') {
					uni.showToast({
						title: '请输入详细地址',
						icon: 'none'
					})
					return
				}
				if (!this.formData.camperBirthday.includes(' 00:00:00')) {
					this.formData.camperBirthday += " 00:00:00"
				}
				this.middle.postJson(this.id ? "/camper/update" : "/camper/add", this.formData).then(res => {
					if (res.code == 200) {
						this.middle.success(res.msg)
					}
				})

			},
			// 获取营员详情
			// #ifdef APP-PLUS
			// 获取选择的地区
			handleGetRegion(region) {
				this.region = region
			},
			// #endif
			// 获取营员数据
			getCityList: function() {
				let that = this;
				getCity().then(res => {
					this.district = res.data;
					let oneDay = 24 * 3600 * 1000;
					// this.$Cache.set('cityList', JSON.stringify(res.data)); //设置不过期时间的方法 
					this.$Cache.setItem({
						name: 'cityList',
						value: res.data,
						expires: oneDay * 7
					}); //设置七天过期时间
					that.initialize();
				})
			},
			initialize: function() {
				let that = this,
					province = [],
					city = [],
					area = [];
				if (that.district.length) {
					let cityChildren = that.district[0].child || [];
					let areaChildren = cityChildren.length ? (cityChildren[0].child || []) : [];
					that.district.forEach(function(item) {
						province.push(item.name);
					});
					cityChildren.forEach(function(item) {
						city.push(item.name);
					});
					areaChildren.forEach(function(item) {
						area.push(item.name);
					});
					this.multiArray = [province, city, area]
				}
			},
			bindRegionChange: function(e) {
				let multiIndex = this.multiIndex,
					province = this.district[multiIndex[0]] || {
						child: []
					},
					city = province.child[multiIndex[1]] || {
						cityId: 0
					},
					multiArray = this.multiArray,
					value = e.detail.value;

				this.region = [multiArray[0][value[0]], multiArray[1][value[1]], multiArray[2][value[2]]]
				this.cityId = city.cityId
				this.valueRegion = [0, 0, 0]
				this.initialize();
			},
			bindMultiPickerColumnChange: function(e) {
				let that = this,
					column = e.detail.column,
					value = e.detail.value,
					currentCity = this.district[value] || {
						child: []
					},
					multiArray = that.multiArray,
					multiIndex = that.multiIndex;
				multiIndex[column] = value;
				switch (column) {
					case 0:
						let areaList = currentCity.child[0] || {
							child: []
						};
						multiArray[1] = currentCity.child.map((item) => {
							return item.name;
						});
						multiArray[2] = areaList.child.map((item) => {
							return item.name;
						});
						break;
					case 1:
						let cityList = that.district[multiIndex[0]].child[multiIndex[1]].child || [];
						multiArray[2] = cityList.map((item) => {
							return item.name;
						});
						break;
					case 2:

						break;
				}
				// #ifdef MP || APP-PLUS
				this.$set(this.multiArray, 0, multiArray[0]);
				this.$set(this.multiArray, 1, multiArray[1]);
				this.$set(this.multiArray, 2, multiArray[2]);
				// #endif
				// #ifdef H5
				this.multiArray = multiArray;
				// #endif
				this.multiIndex = multiIndex
				// this.setData({ multiArray: multiArray, multiIndex: multiIndex});
			},
			// 授权回调
			onLoadFun: function() {
				this.getUserAddress();
			},
			// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e
			},
			toggleTab(str) {
				this.$refs[str].show();
			},
			onConfirm(val) {
				this.region = val.checkArr[0] + '-' + val.checkArr[1] + '-' + val.checkArr[2];
			},
			getUserAddress: function() {
				if (!this.id) return false;
				let that = this;
				this.middle.post("/camper/getById", {
					camperId: this.id
				}).then(res => {
					console.log(res)
					this.formData = res.data
				})
				// getAddressDetail(this.id).then(res => {
				// 	let region = [res.data.province, res.data.city, res.data.district];
				// 	that.$set(that, 'userAddress', res.data);
				// 	that.$set(that, 'region', region);
				// 	that.city_id = res.data.cityId
				// });
			},
			chooseLocation: function() {
				uni.chooseLocation({
					success: (res) => {
						this.$set(this.userAddress, 'detail', res.address.replace(/.+?(省|市|自治区|自治州|县|区)/g,
							''));
					}
				})
			},
			// 导入共享营员（小程序）
			getWxAddress: function() {
				let that = this;
				uni.authorize({
					scope: 'scope.address',
					success: function(res) {
						uni.chooseAddress({
							success: function(res) {
								let addressP = {};
								addressP.province = res.provinceName;
								addressP.city = res.cityName;
								addressP.district = res.countyName;
								addressP.cityId = 0;
								editAddress({
									address: addressP,
									isDefault: 1,
									realName: res.userName,
									postCode: res.postalCode,
									phone: res.telNumber,
									detail: res.detailInfo,
									id: 0
								}).then(res => {
									setTimeout(function() {
										if (that.cartId) {
											let cartId = that.cartId;
											let pinkId = that.pinkId;
											let couponId = that.couponId;
											that.cartId = '';
											that.pinkId = '';
											that.couponId = '';
											uni.navigateTo({
												url: '/pages/users/order_confirm/index?cartId=' +
													cartId +
													'&addressId=' + (
														that.id ? that
														.id :
														res.data
														.id) +
													'&pinkId=' +
													pinkId +
													'&couponId=' +
													couponId +
													'&secKill=' + that
													.secKill +
													'&combination=' +
													that.combination +
													'&bargain=' + that
													.bargain
											});
										} else {
											uni.navigateBack({
												delta: 1
											});
										}
									}, 1000);
									return that.$util.Tips({
										title: "添加成功",
										icon: 'success'
									});
								}).catch(err => {
									return that.$util.Tips({
										title: err
									});
								});
							},
							fail: function(res) {
								if (res.errMsg == 'chooseAddress:cancel') return that.$util
									.Tips({
										title: '取消选择'
									});
							},
						})
					},
					fail: function(res) {
						uni.showModal({
							title: '您已拒绝导入微信营员权限',
							content: '是否进入权限管理，调整授权？',
							success(res) {
								if (res.confirm) {
									uni.openSetting({
										success: function(res) {}
									});
								} else if (res.cancel) {
									return that.$util.Tips({
										title: '已取消！'
									});
								}
							}
						})
					},
				})
			},
			// 导入共享营员（微信）；
			getAddress() {
				let that = this;
				that.$wechat.openAddress().then(userInfo => {
					// open();
					editAddress({
							id: this.id,
							realName: userInfo.userName,
							phone: userInfo.telNumber,
							address: {
								province: userInfo.provinceName,
								city: userInfo.cityName,
								district: userInfo.countryName,
								cityId: 0
							},
							detail: userInfo.detailInfo,
							isDefault: 1,
							postCode: userInfo.postalCode
						})
						.then(() => {
							setTimeout(function() {
								if (that.cartId) {
									let cartId = that.cartId;
									let pinkId = that.pinkId;
									let couponId = that.couponId;
									that.cartId = '';
									that.pinkId = '';
									that.couponId = '';
									uni.navigateTo({
										url: '/pages/users/order_confirm/index?cartId=' +
											cartId + '&addressId=' + (that.id ? that.id :
												res.data
												.id) + '&pinkId=' + pinkId + '&couponId=' +
											couponId + '&secKill=' + that.secKill +
											'&combination=' + that.combination + '&bargain=' +
											that.bargain
									});
								} else {
									uni.navigateTo({
										url: '/pages/users/user_address_list/index'
									})
									// history.back();
								}
							}, 1000);
							// close();
							that.$util.Tips({
								title: "添加成功",
								icon: 'success'
							});
						})
						.catch(err => {
							// close();
							return that.$util.Tips({
								title: err || "添加失败"
							});
						});
				}).catch(err => {
					console.log(err);
				});
			},
			/**
			 * 提交用户添加营员
			 * 
			 */
			formSubmit: function(e) {
				let that = this,
					value = e.detail.value;
				if (!value.realName) return that.$util.Tips({
					title: '请填写收货人姓名'
				});
				if (!value.phone) return that.$util.Tips({
					title: '请填写联系电话'
				});
				if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(value.phone)) return that.$util.Tips({
					title: '请输入正确的手机号码'
				});
				if (that.region == '省-市-区') return that.$util.Tips({
					title: '请选择所在地区'
				});
				if (!value.detail) return that.$util.Tips({
					title: '请填写详细营员'
				});
				value.id = that.id;
				let regionArray = that.region;
				value.address = {
					province: regionArray[0],
					city: regionArray[1],
					district: regionArray[2],
					cityId: that.cityId,
				};
				value.isDefault = that.userAddress.isDefault;

				uni.showLoading({
					title: '保存中',
					mask: true
				})
				editAddress(value).then(res => {
					if (that.id)
						that.$util.Tips({
							title: '修改成功',
							icon: 'success'
						});
					else
						that.$util.Tips({
							title: '添加成功',
							icon: 'success'
						});
					setTimeout(function() {
						if (that.preOrderNo > 0) {
							uni.redirectTo({
								url: '/pages/users/order_confirm/index?preOrderNo=' + that
									.preOrderNo + '&addressId=' + (that.id ? that.id : res.data
										.id)
							})
						} else {
							// #ifdef H5
							return history.back();
							// #endif
							// #ifndef H5
							return uni.navigateBack({
								delta: 1,
							})
							// #endif
						}
					}, 1000);
				}).catch(err => {
					return that.$util.Tips({
						title: err
					});
				})
			},
			ChangeIsDefault: function(e) {
				this.$set(this.userAddress, 'isDefault', !this.userAddress.isDefault);
			}
		}
	}
</script>

<style scoped lang="scss">
	.required::after {
		content: '*';
		margin-left: 5rpx;
		color: red;
	}

	.hobby-wait {
		margin-left: 220rpx;
		display: flex;
	}

	.hobby-detail {
		border-radius: 10rpx;
		border: 2rpx solid #d4d4d4;
		padding: 5rpx 20rpx;
		margin: 0 20rpx 16rpx 0;
	}

	.hobby-detail:active {
		background-color: #ccc;
	}

	.addAddress {
		padding-top: 20rpx;
	}

	.addAddress .list {
		background-color: #fff;
		padding: 0 24rpx;
	}

	.addAddress .list .item {
		border-top: 1rpx solid #eee;
		height: 90rpx;
		line-height: 90rpx;
	}

	.addAddress .list .item .name {
		width: 150rpx;
		font-size: 30rpx;
		color: #333;
	}

	.name {
		min-width: 220rpx;
		width: max-content;
		font-size: 30rpx;
		color: #333;
		font-weight: 500;
	}

	.addAddress .list .item .address {
		flex: 1;
		margin-left: 50rpx;
	}

	.addAddress .list .item input {
		width: 405rpx;
		font-size: 30rpx;
		font-weight: 400;
	}

	.addAddress .list .item .placeholder {
		color: #ccc;
	}

	.addAddress .list .item picker .picker {
		width: 410rpx;
		font-size: 30rpx;
	}

	.addAddress .default {
		padding: 0 30rpx;
		height: 90rpx;
		background-color: #fff;
		margin-top: 23rpx;
	}

	.addAddress .default checkbox {
		margin-right: 15rpx;
	}

	.addAddress .keepBnt {
		width: 100%;
		height: 86rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 86rpx;
		margin: 80rpx auto 24rpx auto;
		font-size: 32rpx;
		color: #fff;
	}

	.addAddress .wechatAddress {
		width: 690rpx;
		height: 86rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 86rpx;
		margin: 0 auto;
		font-size: 32rpx;
		color: #E93323;
		border: 1px solid #E93323;
	}

	.relative {
		position: relative;
	}

	.icon-dizhi {
		font-size: 44rpx;
		z-index: 100;
	}

	.abs_right {
		position: absolute;
		right: 0;
	}

	.status {
		display: flex;
		width: 750rpx;
		// background-color: #E93323;
		height: var(--status-bar-height);
	}

	.acea-row.row-between-wrapper {
		justify-content: flex-start;
	}
</style>